$(function () {
  //var seq_id = window.location.hash;
  //if(seq_id != null)
  //{
  //	seq = seq_id.substr(1,seq_id.length-1);
  //}

  var seq_id = 3;

  console.log($(".creditor-list"))
  var itemIndex = 0;
  var tabLoadEndArray = [false, false, false];
  var tabScroolTopArray = [0, 0];
  var pageindex = 0;
  var pagesize =2;
  var memberstatus = 0;
  var fIndex = 0;
  var sIndex = 0;
  var tIndex = 0;
  var pagerow;
  // load(memberstatus, itemIndex, pageindex, pagesize);
  //dropload
  var dropload = $('#wrapper').dropload({
    scrollArea: window,
    domDown: {
      domClass: 'dropload-down',
      domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
      domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
      domNoData: '<div class="dropload-noData">已加载完</div>'
    },
    loadDownFn: function (me) {

      if (tabLoadEndArray[itemIndex]) {
        me.resetload();
        me.lock();
        me.noData();
        me.resetload();
        return;
      }


      pageindex++;

      var sval = {
        seq_id: seq_id,
        pageindex: pageindex,
        pagesize: pagesize
      };


      function doCallBack(ret) {
        console.log(ret)
        if (ret.retcode == 0) {
          var Data = Base64.decode(ret.data);
          console.log(Data)
          $(".wrap").show();
          if (ret.data) {
            var result = JSON.parse(Data);


            //标题
            document.title = result.share_title;
            //循环获取内容
            var goodsmodel = result.goodslist;


            var allrows = goodsmodel.allrows;
            var allpages = goodsmodel.allpages;
            var goodslist = goodsmodel.list;

            console.log(result)
            if (allrows == 0) {
              me.lock();
              me.noData();
              tabLoadEndArray[itemIndex] = true;
              me.resetload();
              $('.dropload-down').hide();
            } else {
              $('.dropload-down').show();
            }
            var flagBtn = $(".creditor-list").eq(itemIndex).attr('btn');
            if (allrows == 0 && flagBtn == "false") {
              noRecord($(".creditor-list").eq(itemIndex));
              $('.dropload-down').hide();
            } else {
              $('.dropload-down').show();
            }
            if (allrows < 5) {
              me.lock();
              me.noData();
              tabLoadEndArray[itemIndex] = true;
              me.resetload();
              $('.dropload-down').hide();
            } else {
              $('.dropload-down').show();
            }

            if (allrows > 0) {
              // //将数据填充到模板里
              if (goodsmodel.list.length > 0) {
                var html = templateDate(goodsmodel);
                console.log(html)
                console.log($(".creditor-list").eq(itemIndex))
                $(".creditor-list").eq(itemIndex).append(html);
              }
              if (goodsmodel.list.length < pagesize) {
                me.lock();
                me.noData();
                tabLoadEndArray[itemIndex] = true;
              }
              if (allpages == pageindex) {

                me.lock();
                me.noData();
                tabLoadEndArray[itemIndex] = true;
              }
              me.resetload();


            }


          } else {
            noRecord($(".creditor-list").eq(itemIndex));
            $('.dropload-down').hide();
          }
        } else {
          noRecord($(".creditor-list").eq(itemIndex));
          $('.dropload-down').hide();
        }
      }


      jAjax("huodong.getshare", doCallBack, sval);
    },
    threshold: 0
  });

  function templateDate(data) {
    var htmlfinborListData = template("allList", data);
    return htmlfinborListData;
  }

  // ==================tab切换=====
  //tab切换
  var experienceFlag = true;
  $(".tab-bar ul li").click(function () {

    tabScroolTopArray[itemIndex] = $(window).scrollTop();
    itemIndex = $(".tab-bar ul li").index($(this));
    var index = $(this).index();
    var $this = $(this);
    $(".tab-bar ul li").eq(index).addClass("current").siblings().removeClass("current");
    $('.data-content').eq(itemIndex).show().siblings('.data-content').hide();
    curPage = index + 1;
    if (!tabLoadEndArray[itemIndex]) {
      dropload.unlock();
      dropload.noData(false);
    } else {
      dropload.lock('down');
      dropload.noData();
      // if ($('#list li').length <= 5) {
      //     $('.dropload-down').hide();
      // } else {
      //     $('.dropload-down').show();
      // }
    }
    dropload.resetload();
  })

});